package com.dianxin.secure.model;


import org.msgpack.annotation.Message;

@Message
public class Secure {
	private String  path;
	private String action;
	private String name;
    private String type;

    private   String fileKey ;
    private   String totalKey ;

    public  Secure(){
    }

    Secure(String type){
       this.type = type;
       this.fileKey = type+"File:";
       this.totalKey = type+"s";
    }

     public static    Secure user(){
             return  new    Secure("user");
       }

    public   static Secure group(){
        return  new    Secure("group");
    }


	
	public String getPath() {
		return path;
	}
	public void setPath(String path) {
		this.path = path;
	}
	public String getAction() {
		return action;
	}
	public void setAction(String action) {
		this.action = action;
	}
	@Override
	public String toString() {
		return "path:"+getPath()+"  action"+getAction()+"  UserName:"+getName();
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	
	@Override
	public boolean equals(Object obj) {
		if(obj==null){
			return false;
		}
		Secure that=(Secure)obj;
		if(        that.getName().equals(this.getName())
				&& that.getAction().equals(this.getAction())
				&& that.getPath().equals(this.getPath())
				){
			return true;
		}
		return false;
	}
	
	public boolean implies(Secure that) {
	    if (that != null) {
	    	int action=Integer.valueOf(this.action);
	    	int thatAction=Integer.valueOf(that.getAction());
	       if( (that.getName().equals(this.getName())
	    		    && (action & thatAction) == thatAction)
					&& that.getPath().equals(this.getPath())){
	    	   return true;
	       }
					
	    }
	    return false;
	  }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getFileKey() {
        return fileKey;
    }

    public void setFileKey(String fileKey) {
        this.fileKey = fileKey;
    }

    public String getTotalKey() {
        return totalKey;
    }

    public void setTotalKey(String totalKey) {
        this.totalKey = totalKey;
    }
}
